package kr.saeildamil.androidstudy.ch12;

import java.util.ArrayList;

import kr.saeildamil.androiddforstudy.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class ListViewTest extends Activity {
	String[] arr;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch12_listview_test);
		// arr = getResources().getStringArray(R.array.country);

		// 원본 데이터

		
		 final ArrayList<String> arList = new ArrayList<String>();
		  arList.add("이순신"); arList.add("강감찬"); arList.add("을지문덕");
		  arList.add("김유신"); arList.add("연개소문"); arList.add("세종대왕");
		 
		// String[] arList = { "이순신", "강감찬", "을지문덕", "김유신", "연개소문", "세종대왕" };
		// 결과는 동일하게 나오지만, 정적이므로...Res 에 추가해주는 게 옳다;

		// ArrayAdapter

		
		  ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
		  android.R.layout.simple_list_item_1, arList);
		 

	/*	ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
				this, R.array.country,
				// android.R.layout.simple_list_item_multiple_choice);
				android.R.layout.simple_list_item_1);
*/
		// Adapter 를 ListView 에 연결;
		ListView list = (ListView) findViewById(R.id.ch12_listviewtest_list);
		list.setAdapter(adapter);

		list.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position,
					long id) {
				// String str = "position : " + position + ", id : " + id + ", 항목의 값:" + arr[position];
				String str = arList.get(position);				
				Toast.makeText(ListViewTest.this, str, Toast.LENGTH_LONG)
						.show();
			};

			// list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
			// 설정해도 R.layout.simple_list 1의 성향때문에 영향을 줄 수 없음;
			/*
			 * list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
			 * list.setDivider(new ColorDrawable(Color.BLUE));
			 * list.setDividerHeight(5);
			 */

		});
	}
}
